<template>
    <div>
        <div>
            <mt-header title="用户登录">
                <router-link to="/" slot="left">
                    <mt-button icon="back">返回</mt-button>
                </router-link>
                <mt-button icon="more" slot="right"></mt-button>
            </mt-header>
        </div>
        <div>
            <mt-field label="用户名" placeholder="请输入用户名" v-model="username"></mt-field>
            <mt-field label="密码" placeholder="请输入密码" type="password" v-model="password"></mt-field>
            <mt-button type="primary" @click.native="login">登录</mt-button>
        </div>
    </div>
</template>

<script>
    export default {
        name: "Login",
        data(){
            return {
                username: '',
                password: '',
                role: 'student'
            }
        },
        methods: {
            // 用户登录
            login: function(){
                let vm = this
                this.$axios.post('/login',{
                    name: vm.username,
                    pwd: vm.password,
                    role: vm.role
                }).then(function (resp) {
                    console.log(resp.data)
                })
            },
            test: function () {
                var xhr = new XMLHttpRequest();
                xhr.open('GET', 'http://localhost:8080/websit/query/test',true);
                xhr.send();
                xhr.onreadystatechange=function() {
                    if(xhr.readyState == 4) {
                        if(xhr.status == 200) {
                            console.log(xhr.responseText);
                        }
                    }
                }
            }
        }
    }
</script>

<style scoped>

</style>